package com.autumn.annotations.bean.config;

import com.autumn.annotations.demos.Person;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;

/**
 * ClassName: ScopeDemoConfig
 *
 * @Description:
 * @Author: wangqiuyang
 * @Date: 2021/12/28 下午4:09
 * History:
 * <author>          <time>          <version>          <desc>
 * wangqiuyang    2021/12/28 下午4:09   @Version 1.0        描述
 */
@Configuration
public class ScopeDemoConfig {
    /*
        @see ConfigurableBeanFactory#SCOPE_PROTOTYPE  -> singleton 单实例的
        @see ConfigurableBeanFactory#SCOPE_SINGLETON  -> prototype 多实例的
        @see org.springframework.web.context.WebApplicationContext#SCOPE_REQUEST 同一个request中相同
        @see org.springframework.web.context.WebApplicationContext#SCOPE_SESSION 同一个session中相同
    */
    @Scope(value = "singleton")
    @Bean(value = "person1")
    Person person1 (){
        System.out.println("person ... 单例");
        return new Person("王秋阳",18);
    }

    @Scope(value = "prototype")
    @Bean(value = "person2")
    Person person2 (){
        System.out.println("person ... 多实例");
        return new Person("叶秋蓉",18);
    }

    @Scope(value = "singleton")
    @Lazy
    @Bean(value = "person3")
    Person person3 (){
        System.out.println("person ... 单例 懒加载");
        return new Person("青维敏",90);
    }
}
